// ========== Copyright Header Begin ==========================================
// 
// OpenSPARC T1 Processor File: Ni_System.cc
// Copyright (c) 2006 Sun Microsystems, Inc.  All Rights Reserved.
// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
// 
// The above named program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License version 2 as published by the Free Software Foundation.
// 
// The above named program is distributed in the hope that it will be 
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
// 
// You should have received a copy of the GNU General Public
// License along with this work; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
// 
// ========== Copyright Header End ============================================
/************************************************************************
**  
**  Copyright (C) 2002, Sun Microsystems, Inc.
**
**  Sun considers its source code as an unpublished, proprietary
**  trade secret and it is available only under strict license provisions.
**  This copyright notice is placed here only to protect Sun in the event 
**  the source is deemed a published work. Disassembly, decompilation,
**  or other means of reducing the object code to human readable form
**  is prohibited by the license agreement under which this code is
**  provided to the user or company in possession of this copy."
**
*************************************************************************/
#include "Ni/Ni_System.h"
#include "Memory/GenericMemAdapter.h"
#include "StdMacros.h"
#include "Util/Counter.h"
#include <sstream>
#include <fstream>

using namespace std;
using namespace Riesling;

Ni_System::Ni_System()
 : 
  ram_( 04 )
{
    addressSpace_.registerMemInterface( 0x0, 0x7ffffffffffull, &ram_, "Cacheable Physical Address Space" );

    // PA[42:41] = 2'b00 or 2'b01, PA[40:36] = AGENT_ID, PA[35:0] == 64GB of DRAM
    //addressSpace_.registerMemInterface( 0x0, 0x3ffffffffffull, &ram_, "Cacheable Physical Address Space" );
    // PA[42:41] = 2'b10,          PA[40:28] = 13'b0,    PA[27:23] = AGENT_ID, PA[22:0] == 8MB of NC memory
    //addressSpace_.registerMemInterface( 0x40000000000ull, 0xfffffff, &ncConfigReg_, "Configuration Registers" );
    // PA[42:41] = 2'b11,          PA[40:36] = AGENT_ID,  PA[35:0] = 64GB of NC memory 
    //addressSpace_.registerMemInterface( 0x40000000000ull, 0xfffffff, &ncConfigReg_, "NC Memory or I/O" );

    reg_.addInstance( "cacheable ram", SimRegistry::CACHEABLE_RAM, &ram_ );
}

void
Ni_System::loadMemdatImage( const std::string &fileName )
{
    ifstream imgFile( fileName.c_str() );
    if( !imgFile ){
	RIESLING_THROW_INVALID_ARGUMENT(string("Unable to open file \"").
	    append(fileName).append("\" for read." ));
    }

    GenericMemAdapter imgAdapter( imgFile );
    ram_.init( imgAdapter );
    imgFile.close();
}

uint64_t
Ni_System::getThisPtr()
{
    return (uint64_t)this;
}



